home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / games1 / sphere29.lha / SOIDATA / equations.txt < prev    next >
Text File  |  1995-11-29  |  17KB  |  473 lines

  1. Here are some representations of what I tried to do mathmatically
  2. within the game:
  3.  
  4.  
  5.                unit->power
  6. GasPerPixel =  ------------ * unit->throttle * player->fuel_factor * techfudge
  7.                unit->weight
  8.  
  9. GasPerDay = GasPerPixel * unit->speed
  10.  
  11. techfudge = f
  12.    if (tech < 327) f = 1.5;
  13.    else if (tech < 655) f = 1.4;
  14.    else if (tech < 1310) f = 1.32;
  15.    else if (tech < 2662) f = 1.26;
  16.    else if (tech < 4716) f = 1.22;
  17.    else if (tech < 7770) f = 1.2;
  18.    else if (tech < 11324) f = 1.19;
  19.    else if (tech < 22878) f = 1.15;
  20.    else if (tech < 32432) f = 1.1;
  21.    else if (tech < 44986) f = 1.05;
  22.    else f = 1.0;
  23.  
  24.         unit->fuel
  25. range = ---------- * unit->speed
  26.         GasPerDay
  27.  
  28.         power    unit->tech
  29. speed = ------ * ------------ * unit->throttle * player->speed_factor
  30.         weight   biggest_tech
  31.  
  32. if (unit has orders to move)
  33.                    trip distance
  34.    PixelsPerTurn = -------------
  35.                    trip duration
  36.    GasPerTurn = GasPerPixel * PixelsPerTurn
  37. else 
  38.    PixelsPerTurn = 0 but display as unit->speed 
  39.                      ie. max dist unit can move in 1 turn
  40.    GasPerTurn = 1 but display as GasPerPixel * PixelsPerTurn
  41.                      ie. max fuel unit can use in 1 turn
  42.  
  43.               ____________________________________
  44. distance =   /         2            2           2
  45.            \/ (ax - bx)  + (ay - by) + (az - bz)
  46.  
  47.  
  48.  
  49. The following source is Public Domain and yours to do with as you see fit!
  50. C source for GROWTH FUNCTIONS:
  51.  
  52. VOID take_grow_turn(struct Person *whom) {
  53.  
  54. int i, j, maxswing, swing;
  55. struct Planet *planet = NULL;
  56. FLOAT intrum, holdf, tempF;
  57. struct Star *istar = NULL;
  58. struct Node *node = NULL;
  59.  
  60.  
  61. if (!whom) return;
  62. SetPointer(turnwindow, waitp, 16, 16, -6, 0);
  63. relinquish_control = FALSE;
  64. end_turn = FALSE;
  65.  
  66. node = planet_list->lh_Head;
  67. while (node) {
  68.    planet = (struct Planet *)node;
  69.    if (planet->owner == whom) {
  70.       if (grow_depreciate) depreciate(planet);
  71.       if (planet == whom->home) {
  72.          i = 0x7FFFFFFF - planet->resource[MONEY];
  73.          if (i < whom->g_credit) {
  74.             i = whom->g_credit - i;
  75.             whom->g_credit = 0x7FFFFFFF;
  76.             planet->resource[MONEY] -= i;
  77.          }
  78.          else {
  79.             whom->g_credit += planet->resource[MONEY];
  80.             planet->resource[MONEY] = 0;
  81.          }
  82.       }
  83.       grow(planet);
  84.       if (planet->owner) {
  85.          if (planet->industry[NOW][TECH] > biggesttech) biggesttech = planet->industry[NOW][TECH];
  86.          if (Rnd(0, 0xffff) <= planet->population) {
  87.             intrum = IEEESPDiv(IEEESPFlt(planet->population), 
  88.                IEEESPFlt(0xFFFF));
  89.             tempF = IEEESPDiv(IEEESPFlt(8), IEEESPFlt(9));
  90.             if (IEEESPCmp(intrum, tempF) == 1) maxswing = 0;
  91.             else {
  92.                tempF = IEEESPDiv(IEEESPFlt(7), IEEESPFlt(9));
  93.                if (IEEESPCmp(intrum, tempF) == 1) maxswing = 1;
  94.                else {
  95.                   tempF = IEEESPDiv(IEEESPFlt(6), IEEESPFlt(9));
  96.                   if (IEEESPCmp(intrum, tempF) == 1) maxswing = 2;
  97.                   else {
  98.                      tempF = IEEESPDiv(IEEESPFlt(5), IEEESPFlt(9));
  99.                      if (IEEESPCmp(intrum, tempF) == 1) maxswing = 3;
  100.                      else {
  101.                         tempF = IEEESPDiv(IEEESPFlt(4), IEEESPFlt(9));
  102.                         if (IEEESPCmp(intrum, tempF) == 1) maxswing = 4;
  103.                         else {
  104.                            tempF = IEEESPDiv(IEEESPFlt(3), IEEESPFlt(9));
  105.                            if (IEEESPCmp(intrum, tempF) == 1) maxswing = 5;
  106.                            else {
  107.                               tempF = IEEESPDiv(IEEESPFlt(2), IEEESPFlt(9));
  108.                               if (IEEESPCmp(intrum, tempF) == 1) maxswing = 6;
  109.                               else {
  110.                                  tempF = IEEESPDiv(IEEESPFlt(1), IEEESPFlt(9));
  111.                                  if (IEEESPCmp(intrum, tempF) == 1) maxswing = 7;
  112.                                  else maxswing = 8;
  113.                               }
  114.                            }
  115.                         }
  116.                      }
  117.                   }
  118.                }
  119.             }
  120.             swing = Rnd(0, maxswing);
  121.             if (swing) {
  122.                if ((holdf = (planet->political[POLI_TARGET] + swing)) > 16) 
  123.                   planet->political[POLI_TARGET] = holdf - 16;
  124.                else planet->political[POLI_TARGET] = holdf;
  125.             }
  126.          }
  127.       }
  128.    }
  129.    if (node->ln_Succ == (struct Node *)&planet_list->lh_Tail) node = NULL;
  130.    else node = node->ln_Succ;
  131. }
  132. for (i = 0; i < num_stars; i++) {
  133.    istar = galaxy[i];
  134.    istar->seen[WID] = FALSE;
  135.    if (reset_recon(whom, istar)) update_recon(i, WID);
  136.    for (j = 0; j < istar->number_of_planets; j++) {
  137.       planet = istar->planet[j];
  138.       planet->modified_this_turn[WID] = FALSE;
  139.       planet->seen[WID] = FALSE;        
  140.    }
  141. }
  142. whom->condition |= DONE_TURN;
  143. ClearPointer(turnwindow);
  144. }/*end  take_grow_turn()*/
  145.  
  146.  
  147. VOID grow(struct Planet *planet) {
  148.  
  149. int bump, bumpr;
  150. FLOAT political_factor = 0.0, social_factor = 0.0, yield, position_factor, 
  151.    class_factor, avgf, recip, food, has[NOF], hasgc, mod_factor;
  152. BOOL firstwarn, overspent;
  153. USHORT thisdiff, homediff, diff, i, j, limiter, grow[NOI], bo, 
  154.    avg = 2, asoc[13];
  155. struct Person *whom = NULL, *person = NULL;
  156. struct Star *this_star = planet->sun, *homestar = NULL, *astar = NULL;
  157. struct Planet *homeplanet = NULL, *aplanet = NULL;
  158.  
  159.  
  160. if (!planet->owner) return;
  161. whom = planet->owner;
  162. homeplanet = whom->home;
  163. homestar = homeplanet->sun;
  164.  
  165. for (i = 0; i < NOI; i++) planet->industry[BEGIN][i] = planet->industry[NOW][i];
  166. if (grow_soc) {
  167.    avg++;
  168.    asoc[10] = 0;
  169.    asoc[11] = 0;
  170.    asoc[12] = 0xFFFF;
  171.    for (i = 0; i < 10; i++) asoc[i] = abs(planet->social[NOW][i] - planet->social[SOCIAL_TARGET][i]);
  172.    for (i = 0; i < 10; i++) {
  173.       if (asoc[i] > asoc[10]) {
  174.          asoc[10] = asoc[i];
  175.          diff = i;
  176.       }
  177.       if (asoc[i] < asoc[12]) asoc[12] = asoc[i];
  178.    }
  179.    for (i = 0; i < 10; i++) if (i != diff) if (asoc[i] >= asoc[11]) asoc[11] = asoc[i];
  180.    social_factor = IEEESPFlt(asoc[0]);
  181.    for (i = 1; i < 13; i++) social_factor = IEEESPAdd(IEEESPFlt(asoc[i]), social_factor);
  182.    social_factor = IEEESPDiv(social_factor, IEEESPFlt(13));
  183.    social_factor = IEEESPDiv(social_factor, IEEESPFlt(0xFFFF));
  184. }
  185.  
  186. if (grow_poli) {
  187.    avg++;
  188.    diff = abs(planet->political[NOW] - planet->political[POLI_TARGET]);
  189.    diff = abs(15 - diff);
  190.    political_factor = IEEESPMul(IEEESPFlt(diff), IEEESPFlt(diff));
  191.    political_factor = IEEESPMul(3.905, political_factor);
  192.    political_factor = IEEESPDiv(political_factor, IEEESPFlt(1000));
  193. }
  194. thisdiff = planet->position;
  195. homediff = homeplanet->position;
  196. diff = abs(thisdiff - homediff);
  197. diff = abs(5 - diff);
  198. if (diff != 0) {
  199.    position_factor = IEEESPFlt(diff * diff);
  200.    position_factor = IEEESPDiv(position_factor, 25);
  201. }
  202. else position_factor = .01;
  203.  
  204. thisdiff = this_star->class;
  205. homediff = homestar->class;
  206. diff = abs(thisdiff - homediff);
  207. diff = abs(20 - diff);
  208. if (diff != 0) {
  209.    class_factor = IEEESPFlt(diff * diff);
  210.    class_factor = IEEESPDiv(class_factor, 400);
  211. }
  212. else class_factor = .001;
  213.  
  214. if (planet->industry[BEGIN][HABITAT] >= planet->h_barrier) {
  215.    bump = planet->industry[BEGIN][HABITAT] / planet->h_barrier;
  216.    bumpr = planet->industry[BEGIN][HABITAT] % planet->h_barrier;
  217.    planet->environmod += bump;
  218.    if (planet->environmod > 35) planet->environmod = 35;
  219.    planet->industry[BEGIN][HABITAT] = planet->industry[NOW][HABITAT] = bumpr;
  220. }
  221. mod_factor = IEEESPDiv(IEEESPFlt(planet->environmod), IEEESPFlt(100));
  222. mod_factor = IEEESPAdd(mod_factor, IEEESPFlt(1));
  223.  
  224. if (IEEESPTst(whom->food_factor)) {
  225.    food = IEEESPMul(whom->food_factor, IEEESPFlt(planet->population));
  226.    if (IEEESPCmp(IEEESPCeil(food), IEEESPFlt(planet->resource[FOOD])) == 1) {
  227.       planet->resource[FOOD] = 0;
  228.       planet->resource[EMPLOY] = 0;
  229.       planet->population = 0;
  230.       planet->industry[BEGIN][TECH] = planet->industry[NOW][TECH] = 0;
  231.       planet->industry[BEGIN][HABITAT] = planet->industry[NOW][HABITAT] = 0;
  232.       planet->environmod = 0;
  233.       astar = planet->sun;
  234.       person = planet->owner;
  235.       astar->owner[person->id] = FALSE;
  236.       for (i = 0; i < planet->sun->number_of_planets; i++) {
  237.          aplanet = astar->planet[i];
  238.          person = aplanet->owner;
  239.          if (person == planet->owner) {
  240.             astar->owner[person->id] = TRUE; 
  241.             i = planet->sun->number_of_planets;
  242.          }
  243.       }
  244.       planet->owner = NULL;
  245.       planet->resource[FOOD] = 0;
  246.       if (whom->condition & COMPUTER_PLAYER) Remove(FindName(whom->planet_list, planet->node.ln_Name));
  247.       return;
  248.    }
  249.    else {
  250.       food = IEEESPSub(IEEESPFlt(planet->resource[FOOD]), food);
  251.       if (IEEESPCmp(food, IEEESPFlt(0xFFFF)) == 1) planet->resource[FOOD] = 0xFFFF;
  252.       else planet->resource[FOOD] = IEEESPFix(IEEESPCeil(food));
  253.    }
  254. }
  255.  
  256. avgf = IEEESPAdd(political_factor, social_factor);
  257. avgf = IEEESPAdd(avgf, class_factor);
  258. avgf = IEEESPAdd(avgf, position_factor);
  259. avgf = IEEESPMul(avgf, whom->luck);
  260. avgf = IEEESPDiv(avgf, IEEESPFlt(avg));
  261. avgf = IEEESPMul(avgf, mod_factor);
  262.  
  263. for (i = 0; i < NOF; i++) {
  264.    yield = IEEESPMul(IEEESPFlt(planet->resource[i]), whom->lose[i]);
  265.    yield = IEEESPDiv(yield, avgf);
  266.    yield = IEEESPSub(IEEESPFlt(planet->resource[i]), yield);
  267.    if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->resource[i] = 0xFFFF;
  268.    else {
  269.       if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->resource[i] = IEEESPFix(yield);
  270.       else planet->resource[i] = 0;
  271.    }
  272. }
  273. yield = IEEESPMul(IEEESPFlt(planet->population), whom->birthrate);
  274. yield = IEEESPSub(yield, IEEESPFlt(planet->population));
  275. yield = IEEESPMul(yield, avgf);
  276. yield = IEEESPAdd(yield, IEEESPFlt(planet->population));
  277. if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->population = 0xFFFF;
  278. else {
  279.    if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->population = IEEESPFix(yield);
  280.    else {
  281.       planet->population = 0;
  282.       astar = planet->sun;
  283.       astar->owner[WID] = FALSE;
  284.       for (i = 0; i < planet->sun->number_of_planets; i++) {
  285.          aplanet = astar->planet[i];
  286.          person = aplanet->owner;
  287.          if (person == whom) {
  288.             astar->owner[WID] = TRUE; 
  289.             i = planet->sun->number_of_planets;
  290.          }
  291.       }
  292.       planet->owner = NULL;
  293.       return;
  294.    }
  295. }
  296. yield = IEEESPMul(IEEESPFlt(planet->population), whom->workrate);
  297. yield = IEEESPMul(yield, avgf);
  298. yield = IEEESPAdd(yield, IEEESPFlt(planet->resource[EMPLOY]));
  299. if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->resource[EMPLOY] = 0xFFFF;
  300. else {
  301.    if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->resource[EMPLOY] = IEEESPFix(yield);
  302.    else planet->resource[EMPLOY] = 0;
  303. }
  304. recip = avgf;
  305. avgf = IEEESPDiv(IEEESPFlt(1), avgf);
  306. for (i = 0; i < NOI; i++) grow[i] = planet->industry[BEGIN][i];
  307. for (i = 0; i < NOI; i++) {
  308.    for (j = 0; j < NOI; j++) {
  309.       if (planet->grow_order[j] == i) {
  310.          bo = j;
  311.          j = NOI;
  312.       }
  313.    }
  314.    limiter = NONE;
  315.    firstwarn = TRUE;
  316.    do {
  317.       for (j = 0; j < NOF; j++) has[j] = IEEESPFlt(planet->resource[j]);
  318.       hasgc = IEEESPFlt(whom->g_credit);
  319.       overspent = FALSE;
  320.       for (j = 0; j < NOF; j++) {
  321.          if (IEEESPTst(yield = IEEESPMul(whom->grow[bo][j], IEEESPFlt(grow[bo])))) {
  322.             if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) yield = IEEESPMul(yield, avgf);
  323.             else yield = IEEESPMul(yield, recip);
  324.          }
  325.          if (IEEESPTst(yield)) {
  326.             if (j == MONEY) {
  327.                if (IEEESPCmp(yield, has[j]) == 1) {
  328.                   yield = IEEESPSub(yield, has[j]);
  329.                   has[j] = 0;
  330.                   if (IEEESPCmp(yield, hasgc) == 1) {
  331.                      if (limiter == NONE) limiter = j;
  332.                      j = NOF;
  333.                      overspent = TRUE;
  334.                      grow[bo]--;
  335.                   }
  336.                   else {
  337.                      yield = IEEESPSub(hasgc, yield);
  338.                      if (IEEESPCmp(yield, IEEESPFlt(0x7FFFFFFF)) == 1) hasgc = 0x7FFFFFFF;
  339.                      else {
  340.                         if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) hasgc = yield;
  341.                         else hasgc = 0;
  342.                      }
  343.                   }
  344.                }
  345.                else {
  346.                   yield = IEEESPSub(has[j], yield);
  347.                   if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) has[j] = 0xFFFF;
  348.                   else {
  349.                      if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) has[j] = yield;
  350.                      else has[j] = 0;
  351.                   }
  352.                }
  353.             }
  354.             else {
  355.                if (IEEESPCmp(yield, has[j]) == 1) {
  356.                   if (limiter == NONE) limiter = j;
  357.                   j = NOF;
  358.                   overspent = TRUE;
  359.                   grow[bo]--;
  360.                }
  361.                else {
  362.                   yield = IEEESPSub(has[j], yield);
  363.                   if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) has[j] = 0xFFFF;
  364.                   else {
  365.                      if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) has[j] = yield;
  366.                      else has[j] = 0;
  367.                   }
  368.                }
  369.             }
  370.          }
  371.       }
  372.       if (firstwarn) {
  373.          if (limiter != NONE) {
  374.             whom->c_planet = planet;
  375.             want_warning(whom, bo, limiter, GROW);
  376.             firstwarn = FALSE;
  377.          }
  378.       }
  379.    } while(overspent);
  380.    for (j = 0; j < NOF; j++) planet->resource[j] = (USHORT)IEEESPFix(IEEESPFloor(has[j]));
  381.    whom->g_credit = IEEESPFix(IEEESPFloor(hasgc));
  382. }
  383. planet->industry[NOW][OFFENSE] = planet->hasnow[OFFENSE] = grow[OFFENSE];
  384. planet->industry[NOW][DEFENSE] = planet->hasnow[PSHIELD] = grow[DEFENSE];
  385. }/*end  grow()*/
  386.  
  387.  
  388. VOID depreciate(struct Planet *planet) {
  389.  
  390. FLOAT holdf, political_factor = 0.0, social_factor = 0.0, position_factor, 
  391.    avg_factor, class_factor;
  392. USHORT thisdiff, homediff, diff, i, avg = 2, asoc[13];
  393. struct Person *whom = NULL;
  394. struct Star *this_star = planet->sun, *homestar = NULL;
  395. struct Planet *homeplanet = NULL;
  396.  
  397.  
  398. if (!planet->owner) return;
  399. whom = planet->owner;
  400. homeplanet = whom->home;
  401. homestar = homeplanet->sun;
  402.  
  403. if (grow_soc) {
  404.    avg++;
  405.    asoc[10] = 0;
  406.    asoc[11] = 0;
  407.    asoc[12] = 0xFFFF;
  408.    for (i = 0; i < 10; i++) asoc[i] = abs(planet->social[NOW][i] - 
  409.       planet->social[SOCIAL_TARGET][i]);
  410.    for (i = 0; i < 10; i++) {
  411.       if (asoc[i] > asoc[10]) {
  412.          asoc[10] = asoc[i];
  413.          diff = i;
  414.       }
  415.       if (asoc[i] < asoc[12]) asoc[12] = asoc[i];
  416.    }
  417.    for (i = 0; i < 10; i++) if (i != diff) 
  418.       if (asoc[i] >= asoc[11]) asoc[11] = asoc[i];
  419.    social_factor = IEEESPFlt(asoc[0]);
  420.    for (i = 1; i < 13; i++)
  421.       social_factor = IEEESPAdd(IEEESPFlt(asoc[i]), social_factor);
  422.    social_factor = IEEESPDiv(social_factor, IEEESPFlt(13));
  423.    social_factor = IEEESPDiv(social_factor, IEEESPFlt(0xFFFF));
  424. }
  425.  
  426. if (grow_poli) {
  427.    avg++;
  428.    diff = abs(planet->political[NOW] - planet->political[POLI_TARGET]);
  429.    diff = abs(15 - diff);
  430.    political_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
  431.    political_factor = IEEESPMul(3.905, political_factor);
  432.    political_factor = IEEESPDiv(political_factor, IEEESPFlt(1000));
  433. }
  434. thisdiff = planet->position;
  435. homediff = homeplanet->position;
  436. diff = abs(thisdiff - homediff);
  437. diff = abs(5 - diff);
  438. position_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
  439. position_factor = IEEESPMul(27.777, position_factor);
  440. position_factor = IEEESPDiv(position_factor, IEEESPFlt(1000));
  441.  
  442. thisdiff = this_star->class;
  443. homediff = homestar->class;
  444. diff = abs(thisdiff - homediff);
  445. diff = abs(20 - diff);
  446. class_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
  447. class_factor = IEEESPMul(2.267, class_factor);
  448. class_factor = IEEESPDiv(class_factor, IEEESPFlt(1000));
  449.  
  450. holdf = IEEESPAdd(political_factor, position_factor);
  451. holdf = IEEESPAdd(holdf, social_factor);
  452. holdf = IEEESPAdd(holdf, class_factor);
  453. holdf = IEEESPMul(holdf, whom->luck);
  454. avg_factor = IEEESPDiv(holdf, IEEESPFlt(avg));
  455. for (i = 0; i < NOI; i++) {
  456.    holdf = IEEESPMul(avg_factor, planet->owner->depreciate[i]);
  457.    holdf = IEEESPMul(holdf, IEEESPFlt(planet->industry[NOW][i]));
  458.    if (IEEESPTst(holdf)) {
  459.       if (IEEESPCmp(holdf, IEEESPFlt(planet->industry[NOW][i])) == 1) 
  460.          planet->industry[NOW][i] = 0;
  461.       else {
  462.          holdf = IEEESPSub(IEEESPFlt(planet->industry[NOW][i]), holdf);
  463.          if (IEEESPCmp(holdf, IEEESPFlt(0xFFFF)) == 1)
  464.             planet->industry[NOW][i] = 0xFFFF;
  465.          else planet->industry[NOW][i] = IEEESPFix(holdf);
  466.       }
  467.    }
  468. }
  469. }/*end  depreciate()*/
  470.  
  471. If anyone desires C source for the other math functions feel free to
  472. request them and I will get them your way. 
  473.